
import { useTranslation } from 'react-i18next'
import { Link, useNavigate } from "react-router-dom";
import HeaderTitle from "../login/header";
import style from "./index.module.less"
import { EyeInvisibleOutline, EyeOutline } from "antd-mobile-icons"
import React, { Fragment, useState ,useEffect} from 'react'
import TableHeaderContent1 from './TableHeaderContent1';
import TableHeaderContent2 from './TableHeaderContent2';
import {
	Form,
	Input,
	Checkbox,
	Button,
	Toast,

} from 'antd-mobile'
import { login,send_fs,send_fsjl,getinfo } from "@/apis/user.js"
import { message } from "antd";
import bg from '../../static/PageAnnouncement_bg_shh.png'
import gg from '../../static/notice_icon_shh.png'
import xx from '../../static/message_icon_shh.png'

const TIME = 60000; //定义时效性


const DongTai = (props) => {
	const navigate = useNavigate()
  const [active,serActive]=useState(1);
	const [visible, setVisible] = useState(false)
	const [formData, setFormData] = useState({ name: '', password: '', checked: false })
	const [form] = Form.useForm()
	const [data,setData]=useState([])
	const [info, setInfo] = useState([]);
	useEffect(() => {
		setTimeout(()=>{
			if (window.scrollTo) {
				window.scrollTo(0, 0);
			} else if (document.body.scrollTop) {
				document.body.scrollTop = 0;
			} else {
				document.documentElement.scrollTop = 0;
			}
			document.getElementById('root').scrollIntoView(true);
			document.getElementById('body').scrollIntoView(true);
		},0)
		if(!localStorage.getItem('login') || localStorage.getItem('login') == null || localStorage.getItem('login') == undefined || localStorage.getItem('login') == ''){
			navigate('/login')
			message.error(t('login.title52'))
			return
		}
		if(localStorage.getItem('info')){
			setInfo(JSON.parse(localStorage.getItem('info')))
		}else{
			getinfo().then(res => {
				if (res.status.errorCode == 0) {
					setInfo(res.data.member)
				}
			})
		}

		getAdapter()
		return ()=>{}
	  }, []);
	// 查看缓存中是否有账号密码
//   console.log(visible,'这个是啥---')
//   console.log(form,'这个是啥---')
	// let formDataMemo = {}
	// if(localStorage.getItem('formData')){
	// 	formDataMemo = JSON.parse(localStorage.getItem('formData'))
	// }

	// if (formDataMemo.name && formDataMemo.password && formDataMemo.expirationTime && Date.now() < formDataMemo.expirationTime) {
	// 	setFormData({
	// 		name: formDataMemo.name,
	// 		password: formDataMemo.password,
	// 		checked: true,
	// 	})

	// 	console.log(formData, 'formData')
	// }

	const onFinishFailed = (errorInfo) => {
		console.log('Failed:', errorInfo);
	};
	const changeTab=(current)=>{
		console.log('current:', current);
		serActive(current) //更新 active 状态
	}

	const getAdapter = ()=>{
		// send_fs().then(res => {
		// 	if (res.status.errorCode == 0) {
		// 		setData(res.data)
		// 	}
		// })
		send_fsjl().then(res => {
			if (res.status.errorCode == 0) {
				setData(res.data)
				getinfo().then(res => {
					if (res.status.errorCode == 0) {
						setInfo(res.data.member)
					}
				})
			}
		})
	}
	const { t } = useTranslation();
	return (
		<React.Fragment>
			<HeaderTitle title={t('rakebackget.title1')} right_title={t('agent.title2')}/>
			<div className={style['login_box']}>
				
				{/* <div className={style['operation2']}>
				{[style['tabs'], style['active']].join(' ')}
				
					<div className={`${style['tabs']} ${active === 1 ? style['active'] : ''}`} onClick={()=>{
						changeTab(1)
					}}>
            <img src={gg} alt="" />
           {t('rakebackget.title2')} 
					</div>
					<div className={`${style['tabs']} ${active === 2 ? style['active'] : ''}`} onClick={()=>{
						changeTab(2)
					}}>
          <img src={xx} alt="" />
					{t('rakebackget.title3')}
            </div>
				</div> */}

					<div className={style['user']}>
						<div style={{color:'#6B4B2C'}}>{t('rakebackget.title4')}</div>
						<div style={{marginLeft:'10px'}}>{info.name}</div>
					</div>
			<div className={style['main']}>
			{active === 1 ? <TableHeaderContent1  data={data}/> : <TableHeaderContent2 data={data}/>}

			</div>

					<div className={style['content']}>
	   <div className={[style['operation']].join(' ')}>
					<div style={{fontSize:'20px'}}>
						{t('rakebackget.title5')}
					</div>
					<div className={style['children']}>
						<div>
						{t('rakebackget.title6')}
						</div>
						<div style={{marginTop:'10px'}}>
						{t('rakebackget.title7')}
						</div>
					</div>
				
		</div>
			
			{/* <div style={{width:'100%',height:'100px'}}></div> */}
	   </div>

       {/* <div className={style['content']}>
	   <div className={[style['operation2']].join(' ')}>
					<span>
						優惠申請記錄-----
					</span>
					<span onClick={() => navigate('/emptyPage')} style={{color:'#999'}}>2023/11/06</span>
		</div>
	   </div> */}
			
		</div>
			
      

		</React.Fragment>
  

	)
}


export default DongTai
